#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSqlDatabase>
#include <QItemSelection>
#include <QVBoxLayout>
#include "cart.h"
#include "ordermanager.h"  // 添加这行
#include "commentwidget.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr, int userId = 0, const QString &userType = "");
    ~MainWindow();

private slots:
    void onProductSelected(const QItemSelection &selected, const QItemSelection &deselected);
    void onSearchTextChanged(const QString &text);
    void on_cartButton_clicked();
    void on_addToCartButton_clicked();

private:
    Ui::MainWindow *ui;
    QSqlDatabase db;
    int m_userId;
    QString m_userType;
    QPushButton *cartButton;
    QVBoxLayout *productDetailsLayout;

    void setupUI();
    void setupDatabase();
    void loadProducts(const QString &filter = "");
    void disconnectAllButtons();  // 添加方法声明
};
#endif // MAINWINDOW_H
